using System;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;

namespace Send2Sharepoint.Forms
{
    public class TextBoxControl : InputControl
    {
        public TextBoxControl(XmlNode element) : base(element)
        {
            var attributeCollection = element.Attributes;
            string defaultValue = element.ChildNodes[0] != null ? element.ChildNodes[0].InnerText : "";
            var name = attributeCollection["Name"].Value;
            Field = new TextBox
            {
                Name = "controlTxtBox_" + name,
                Size = new Size(250, 22),
                Text = defaultValue
            };
            if (attributeCollection["Type"].Value == "Number")
            {
                Label.Text += (attributeCollection["Percentage"] != null &&
                               attributeCollection["Percentage"].Value == "TRUE")
                                  ? "%"
                                  : "";
            }

            if (attributeCollection["MaxLength"] != null)
                ((TextBox)Field).MaxLength = Int32.Parse(attributeCollection["MaxLength"].Value);

        }
    }
}